
<div id="appSnapshotModal" class="modal fade" data-height="100"
	data-backdrop="static" role="dialog" aria-labelledby="appSnapshotLabel"
	aria-hidden="true" tabindex="-1">
	<input class="In" type="hidden" id="snaphotAppVId"
		value="{{appVersion.id}}" /> <input class="In" type="hidden"
		id="snaphotAttchId" />

	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal"
			aria-hidden="true">×</button>
		<h3 id="appSnapshotLabel" class="text-center">快照上传</h3>
	</div>
	<div class="modal-body" style="height: 100px">
		<div class="text-right pad-st-b5">
			<table class="text-center">
				<tr>
					<td class="bd_sr" width="10%"></td>
					<td class="bd_sr"><div id="snaphotUploadContainer"></div></td>
				</tr>
			</table>
		</div>
	</div>
	<div class="modal-footer">
		<button class="btn btn-common btn-small tls" data-dismiss="modal"
			aria-hidden="true">关闭</button>
		<button class="btn btn-primary btn-small tls" onclick="saveAppSnap()">保存</button>
	</div>
</div>
<script type="text/javascript">
	var popover = function(inputId, content) {
		var options = {
			placement : "bottom",
			content : content
		};
		$('#' + inputId).attr("data-toggle", "popover");
		$('#' + inputId).popover(options);
		$('#' + inputId).popover('show');
	}
	
	$(function() {
		$('#appSnapshotModal').on('hidden', function() {
			$('#snaphotUploadContainerInput').val('');
			$('#snaphotUploadContainerSize').val('');
			$("#snaphotUploadContainerName").val('');
			$("#snaphotAttchId").val('');
		});
		
		var uploader = buildPlupload({
			id : "snaphotUploadContainer",
			elmName : "snapshot",
			targetUrl : "{{ctx}}/mam/attachment/upload",
			filters : [{title : "图片", extensions : "png"}],
			defaultVal : "",
			btnName : "上传快照"
		});
	});

	function saveAppSnap() {
		var value = $('#snaphotUploadContainerInput').val();
		if (value == "") {
			popover("snaphotUploadContainerBtn", "请上传png格式图片");
			return false;
		}
		var data = {
			"appVId": $("#snaphotAppVId").val(),
			"attchmentId": value
		};
		$.ajax({
			async : true,
			type : "POST",
			url : "{{ctx}}/mam/appversions/{{appVersion.platformid}}/snapshot",
			data : data,
			dataType : 'json',
			success : function(result, textStatus) {
				if (result.result == "success") {
					$('#appSnapshotModal').modal("hide");
					bootbox.alert("新增快照成功！",function(){
						window.location.reload();
					});
				} else {
					bootbox.alert("添加失败，请稍后再试！");
				}
			},
			error : function(data, status, e) {
				bootbox.alert("系统繁忙，请稍后再试！");
			}
		});

	}
</script>
